<!--
 * @Descripttion: 
 * @Author: yuxi
 * @Date: 2020-12-02 15:29:24
 * @LastEditors: yuxi
 * @LastEditTime: 2020-12-03 13:11:47
-->
<template>
  <div class="demo">
    <div class="item">
      <div class="title">向上滚动</div>
      <div class="card c1">
        <vue-infinite-scroll :active="data1.length > 0">
          <UserItem v-for="(user) in data1"
                    :key="user.id"
                    :user="user"></UserItem>
        </vue-infinite-scroll>
      </div>
    </div>
    <div class="item">
      <div class="title">实时滚动</div>
      <div class="card c2">
        <VueInfiniteScroll :active="data1.length > 0"
                           :delay="0">
          <UserItem v-for="(user) in data1"
                    :key="user.id"
                    :user="user"></UserItem>
        </VueInfiniteScroll>
      </div>
    </div>
    <div class="item">
      <div class="title">向下滚动</div>
      <div class="card c3">
        <VueInfiniteScroll :active="data1.length > 0"
                           direction="down">
          <UserItem v-for="(user) in data1"
                    :key="user.id"
                    :user="user"></UserItem>
        </VueInfiniteScroll>
      </div>

    </div>
  </div>
</template>

<script>
import VueInfiniteScroll from '../components/VueInfiniteScroll' 
import UserItem from './userItem' 
let Mock  = require('mockjs') 
export default {
  name: 'Demo',
  components:{
    VueInfiniteScroll,
    UserItem
  },
  data() {
    return {
      data1: [],
      data2: [],
      data3: []
    }
  },
  created() {
    this.data1 = Mock.mock({
       'list|20': [{
         'id|+1': 1,
        'name': '@cname',
        'age|20-40': 1,
        'date': Mock.Random.date('yyyy-MM-dd'),
        'address': '@city',
        'gender|0-1': 1
        // 'info': /\w{20, 30}/
      }]
    }).list

    this.data2 = Mock.mock({
       'list|20': [{
         'id|+1': 1,
        'name': '@cname',
        'age|20-40': 1,
        'date': Mock.Random.date('yyyy-MM-dd'),
        'address': '@city',
        'gender|0-1': 1
        // 'info': /\w{20, 30}/
      }]
    }).list
  // Mock.mock({
  //     'name': Mock.Random.first(),
  //     'age|20-40': 1,
  //     'date': Mock.Random.date('yyyy-MM-dd'),
  //     'info': /\w{20, 30}/
  //   })
  },
}
</script>

<style>
html,
body,
#app {
  padding: 0;
  margin: 0;
  background-color: #f8f8f8;
  height: 100%;
}
.demo {
  background-color: #f8f8f8;
}
.item {
  display: inline-block;
  width: 300px;
  height: 500px;
  margin: 20px;
  vertical-align: top;
  overflow: hidden;
}
.card {
  background-color: #fff;
}
.title {
  text-align: left;
  padding: 5px;
  font-size: 18px;
  color: #999;
}
</style>